#!/bin/bash
################### 自动化初始化k8s环境脚本 #####################
# 执行之前：
# 	1. 去除特殊字符：sed -i 's/\r//' init_k8s_env.sh
# 	2. 添加执行权限：chmod +x init_k8s_env.sh
# 执行命令：source init_k8s_env.sh
# 执行之后：
# 脚本说明：
######################################################

echo "----------1.关闭防火墙----------------"
systemctl stop firewalld
systemctl disable firewalld

echo "----------2.关闭selinux----------------"
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0

echo "----------3.关闭sawp----------------"
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab

echo "----------4.设置hostname----------------"
hostnamectl set-hostname k8s-master
#hostnamectl set-hostname k8s-node1
#hostnamectl set-hostname k8s-node2

echo "----------5.添加主机名----------------"
cat >> /etc/hosts << EOF
192.168.14.130 k8s-master 
192.168.14.131 k8s-node1 
192.168.14.132 k8s-node2
EOF

echo "----------6.IPv4 流量传递到 ipv6----------------"
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
# 生效
sysctl --system

echo "----------7.同步机器时间----------------"
yum -y install ntpdate
ntpdate time.windows.com
# 修改时区
rm -f /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
